﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Project_ScansiaPacific
{
    public partial class FrDoiMatKhau : DevComponents.DotNetBar.Office2007Form
    {
        public FrDoiMatKhau()
        {
            InitializeComponent();
        }

        private void bt_DoiMatKhau_Click(object sender, EventArgs e)
        {
            Data dta=new Data();
            string sql_select = @"select UsersName,Password from Users";
            SqlConnection Conn = dta.Connect();
            SqlCommand cmd = new SqlCommand();
            try
            {
                Conn.Open();
                cmd.CommandText = sql_select;
                cmd.Connection = Conn;
                SqlDataReader rd = cmd.ExecuteReader();
                int i = 0;
                while (rd.Read())
                {
                    if (txt_UserName.Text == rd[0].ToString() && txt_Passold.Text == rd[1].ToString())
                    {
                        string update = @"update Users set Password='" + txt_Passnew.Text + "' where UsersName ='" + txt_UserName.Text + "'";
                        dta.Change_data(update);
                        MessageBox.Show("Thay đổi Password thành công");
                        i = 0;
                        break;
                    }
                    else
                        i++;
                }
                if (i > 0)
                    MessageBox.Show("Tên hoặc Mật Mã chưa đúng");
                Conn.Close();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }
    }
}
